-
Notifications
You must be signed in to change notification settings - Fork 45
Add support for forwarding headers from MCP clients to GraphQL APIs #428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
✅ Docs preview readyThe preview is ready to be viewed. View the preview File Changes 0 new, 8 changed, 0 removed
Build ID: a7fa14ebf9e66e0b65c8094e URL: https://www.apollographql.com/docs/deploy-preview/a7fa14ebf9e66e0b65c8094e |
❌ Changeset file missing for PR All changes should include an associated changeset file. |
use crate::auth::ValidToken; | ||
|
||
/// List of header names to forward from MCP clients to GraphQL API | ||
pub type ForwardHeaders = Vec<String>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want any additional validation on the strings being used here? Like size limits, or excludes mcp-session-id
, authorization
, traceparent
, and tracestate
which we tend to handle more as special cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question, @swcollard ! Which of them do you think we should block from forwarding? I guess forwarding mcp-session-id
, traceparent
and tracestate
to downstream APIs could be helpful from the observability perspective? 🤔 We recommend not using this feature for passing through authorization
in the best practices docs, but I think we should still leave it to the user's discretion based on customer feedback.
Fixes #198
Adds opt-in support for dynamic header forwarding, which enables metadata for A/B testing, feature flagging, geo information from CDNs, or internal instrumentation to be sent from MCP clients to downstream GraphQL APIs. It automatically blocks hop-by-hop headers according to the guidelines in RFC 7230, section 6.1, and it only works with the Streamable HTTP transport.
You can configure using the
forward_headers
setting:Please note that this feature is not intended for passing through credentials as documented in the best practices page.
E2E Test
Configure the MCP server to target the Platform API and enable CORS as below, then verify end‑to‑end with MCP Inspector:
With the 3 required headers set in MCP Inspector, tool execution succeeds:
If you configure MCP Inspector with Connection Type = Direct, you can also inspect the MCP call in the browser:
If any required header is missing, the server returns an error: